/**
 * 
 */
package com.morningstar.qs.api.basic.common.excel;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author justin
 * 
 */
public class WorkSheet {
	private String name;
	private Map<Integer,String> titleMap;
	private Map<Integer,Integer> colTypeMap;
	private Map<Integer,Map<Integer,String>> rowMap;
	
	public  WorkSheet(){
		titleMap=new LinkedHashMap<Integer,String>();
		colTypeMap=new LinkedHashMap<Integer,Integer>();
		rowMap=new LinkedHashMap<Integer,Map<Integer,String>>();
	}
	
	public String getName() {
		return name;
	}
	
	/**
	 * set the sheet name
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * set the columns title
	 * @param colNo
	 * @param titleName
	 */
	public void setTitle(int colNo,String titleName){
		titleMap.put(colNo, titleName);
		
	}
	/**
	 * set columns data type if necessary
	 * the data type is defined in ExcelService interface
	 * default data type is string
	 * @param colNo
	 * @param dataType 
	 */
	public  void setColType(int colNo,int dataType){
		colTypeMap.put(colNo, dataType);
	}
	
	public void setCol(int colNo,String titleName,int dataType){
		setTitle(colNo, titleName);
		setColType(colNo, dataType);
	}
	
	/**
	 * set cell data value
	 * @param rowNo
	 * @param col
	 * @param data
	 */
	public void setData(int rowNo,int col,String data){
		if(rowMap.containsKey(rowNo)){
			rowMap.get(rowNo).put(col, data);
		}
		else{
			Map<Integer,String> item=new LinkedHashMap<Integer,String>();
			item.put(col, data);
			rowMap.put(rowNo, item);
		}
	}
	
	public void setData(int rowNo, String[] datas){
		
		if(rowMap.containsKey(rowNo)){
			for(int i=0;i<datas.length;i++){
				rowMap.get(rowNo).put(i, datas[i]);
			}
			
		}
		else{
			Map<Integer,String> item=new LinkedHashMap<Integer,String>();
			for(int i=0;i<datas.length;i++){
				item.put(i, datas[i]);
			}
			rowMap.put(rowNo, item);
		}
	}

	public Map<Integer, String> getTitleMap() {
		return titleMap;
	}

	public Map<Integer, Integer> getColTypeMap() {
		return colTypeMap;
	}

	public Map<Integer, Map<Integer, String>> getRowMap() {
		return rowMap;
	}
	
}
